package com.lq.ecoldchain.base

import android.arch.lifecycle.LifecycleOwner
import android.arch.lifecycle.MutableLiveData
import com.lq.ecoldchain.base.viewmodel.BaseViewModel
import com.lq.ecoldchain.base.viewmodel.addLifecycle

/*
*2018/12/22 0022  16:29
*function by lq
*/
class CommonLoadingViewModel private constructor() : BaseViewModel(), LoadingDelegate {

    private val state: MutableLiveData<CommonLoadingState> = MutableLiveData()

    override fun loadingState(): MutableLiveData<CommonLoadingState> = state

    override fun applyState(state: CommonLoadingState) {
        this.state.postValue(state)
    }

    companion object {
        fun instance(lifecycleOwner: LifecycleOwner) =
                CommonLoadingViewModel().apply {
                    addLifecycle(lifecycleOwner)
                }
    }
}